package Mooc.Chap1;

import java.util.Scanner;

public class _02语句 {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        /*
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();
        if (num > 10) {
            System.out.println(num + ">10");
        } else {
            System.out.println(num + "<=10");
        }
        int num1 = 0, num2 = 0, num3 = 0, num4 = 0;
        int sum = num1 > num2 ? num3 : num4;
        */

        //switch-case
        /*
        int type=4;
        switch (type){
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            case 3:
                System.out.println("3");
                break;
            default:
                System.out.println("v fnhsalmkgjslfjm");
                break;
        }
        */

        //循环
        /*
        while (true) {
            System.out.print("输入数字:");
            Scanner input = new Scanner(System.in);
            int num=input.nextInt();
            if (num>10){
                System.out.println(num+">10");
            }
            else {
                System.out.println(num+"<=10");
            }
        }
       */

        //数数字
        /*
        System.out.print("输入你的数字");
        Scanner input = new Scanner(System.in);
        int num=input.nextInt(),count=0;
        while (num>0){
            count+=1;
            num=num/10;
        }
        System.out.println(count);
        */

        //猜数字
        /*
        System.out.println("输入一个数字[0-1024)");
        int num=(int)(Math.random()*1024+1);//[0,1)
        num=0;
        Scanner input = new Scanner(System.in);
        int ans=input.nextInt(),count=1;
        while (num !=ans) {
            if (num>ans){
                System.out.println("猜错喽！再大一点!");
            }
            else {
                System.out.println("猜错喽！再小一点!");
            }
            ans=input.nextInt();
            count++;
        }
        System.out.println("恭喜你！你只用了"+count+"次就猜出了答案，真是个幸运儿！！！");
        */

        //求所有数平均数
        /*
        System.out.println("请输入数字，输入-1结束计算");
        Scanner input = new Scanner(System.in);
        int num=0, count=0, sum=0;
        num = input.nextInt();
        while (num != -1){
            sum=sum+num;
            count++;
            num = input.nextInt();
        }
        if (count==0){
            System.out.println("0");
        }
        else {
            System.out.println((double)sum/count);
        }
        */

        //1 - n的倒数和
        /*
        System.out.print("输入n:");
        Scanner input = new Scanner(System.in);
        int n=input.nextInt();
        double sum=0;
        for(int i=1;i<=n;i++){
            sum+=1.0/i;
        }
        System.out.println(sum);
        */

        //最大公约数
        /*
        System.out.println("请输入两个数，求两者最大公约数大小");
        Scanner input = new Scanner(System.in);
        int num1=input.nextInt(),num2= input.nextInt(),cnt;
        if (num1==0|num2 == 0){
            System.out.println(num1==0?num2:num1); //三目运算符
        }
        else{
            for (;num2%num1!=0;){
                cnt=num1;
                num1=num2%num1;
                num2=cnt;
            }
            System.out.println(num1);
        }
        */

        //数组 数数字
        /*
        int [] nums=new int[10];
        System.out.print("输入一个数:");
        Scanner input=new Scanner(System.in);
        int num=input.nextInt();
        while (num!=-1) {
            System.out.print("输入一个数:");
            nums[num]++;
            num=input.nextInt();
        }
        for (int i=0;i<10;i++){
            System.out.println(i+"出现"+nums[i]+"次");
        }
        */

        //素数-基础方法一
        /*
        int [] primes=new int[50];
        primes[0]=2;
        int count=1;
        boolean isPrime=true;

        for (int x=3;count<50;x++){
            for (int i=2;i<=Math.sqrt(x);i++){
                if (x%i==0){
                    isPrime=false;
                    break;
                }
            }
            if (isPrime) {
                primes[count]=x;
                count++;
                System.out.println(x);
            }
            isPrime = true;
        }
         */

        //素数-MAIN-LOOP
        /*
        int [] primes=new int[50];
        primes[0]=2;
        int count=1;
        boolean isPrime=true;
        MAIN_LOOP:
        for (int x=3;count<50;x++){
            for (int i=2;i<=Math.sqrt(x);i++){
                if (x%i==0){
                    continue MAIN_LOOP;
                }
            }
            primes[count++]=x;
        }
        for (int k:primes){
            System.out.print(k+" ");
        }
        */

        //素数-去除倍数-100以内素数
        /*
        boolean[] isPrime=new boolean[100];
        for (int i = 0; i < isPrime.length; i++) {
            isPrime[i] = true;
        }
        for (int i = 2; i < isPrime.length; i++) {
            if (isPrime[i]) {
                for (int j = 2; j*i < isPrime.length; j++) {
                    isPrime[i*j] = false;
                }
            }
        }
        for (int i = 2; i < isPrime.length; i++) {
            if (isPrime[i]) {
                System.out.print(i+" ");
            }
        }

         */

        //字符类型
        /*
        char c = 'a';
        char b='\u0041';
        char a=65;
        int i=(int)c;
        System.out.println(c+" "+b+" "+a+" "+i);

         */

        //逃逸字符-无法打印的字符
        /*
        System.out.println("abc");
        System.out.println("abc\b");
        System.out.println("abc\bd");
        System.out.println("abc\t123");
        System.out.println("a\t123");
        System.out.println("\\"+" \""+" \'");

         */

        //包裹类型        Boolean/Character/Integer/Double
        /*
        System.out.println(Integer.MAX_VALUE+"  "+Double.MAX_VALUE);
        System.out.println(Character.isDigit('1'));
        System.out.println(Character.isLetterOrDigit('1'));
        System.out.println(Character.isLowerCase('a'));
        System.out.println(Character.toLowerCase('A'));

         */

        //Math
        /*
        System.out.println(Math.abs(-21));
        System.out.println(Math.round(-21.607));
        System.out.println(Math.random()*100);
        System.out.println(Math.pow(1,3));

         */

        //字符串
        /*
        String s1=new String("a string");
        String s2="hello";
        System.out.println("接下来请输入\"bye\""+12+24+s1+" "+s2+12+24+(12+24));
        Scanner input = new Scanner(System.in);
        String s=input.next();//只读入一个单词（遇到空格结束）
        System.out.println(s);
        System.out.println(s=="bye"); // ==比较地址和内容
        System.out.println(s.equals("bye")); // .equals()只比较内容

         */

        //字符串操作
        /*
        String s1 = "abc";
        String s2 = "abcdedsf";
        System.out.println(s1.compareTo(s2));//按次序比较unicode编码，s1<s2,结果是负；s1=s2,结果是0；s1>s2,结果是正

        String name = "AceLength",
                str1 = "",
                str2;
        System.out.println(name.length() +" "+ str1.length() );

        for (int i = 0; i < name.length(); i++) {
            System.out.println(name.charAt(i));
        }
        //切片
        System.out.println(name.substring(0));//从n号位到末尾
        System.out.println(name.substring(0,1));//[n,m)

        //查找
        System.out.println(name.indexOf('c',0));//左->右查找字符，开始位置可不写
        System.out.println(name.lastIndexOf("ce",0));//右->左逆序，查找字符串也是逆序！！

//        name.startsWith("Ac");
//        name.endsWith("th");
//        name2=name.trim();//去掉两端空格
//        name2=name.replace(str2,str1);


        //switch-case字符串
        str1="this";
        switch (str1){
            case "this":
                break;
            case "that":
                break;
        }
        */
    }
}
